import { Link, useLocation } from 'react-router-dom';

const breadcrumbNameMap: Record<string, string> = {
  '/system': '系统',
  '/device': '设备管理',
  '/device/device-info': '设备信息',
  '/device/device-status': '设备状态',
  '/device/device-config': '设备配置',
  '/key-management': '密钥管理',
  '/log': '日志管理',
  '/log/manage-log': '管理日志',
  '/log/system-log': '系统日志',
  '/log/interface-log': '接口日志',
  '/user-management': '用户管理',
  '/bw-list': '访问控制',
};

const useBreadCrumb = () => {
  const location = useLocation();
  const pathSnippets = location.pathname.split('/').filter((i) => i);
  const breadcrumbItems = pathSnippets.map((_, index) => {
    const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
    let isClickable = true; // 默认可点击
    if (url === '/log' || url === '/device') {
      isClickable = false; // 将 '/log' 和 '/device' 设置为不可点击
    }
    return {
      key: url,
      title: isClickable ? (
        <Link to={url}>{breadcrumbNameMap[url]}</Link>
      ) : (
        <span>{breadcrumbNameMap[url]}</span>
      ),
    };
  });

  return { items: breadcrumbItems };
};

export default useBreadCrumb;
